from abc import ABCMeta, abstractmethod


class Notice:  # 抽象发布者
    def __init__(self):
        self.observers = []  # 用于存储订阅者信息

    def attach(self, obs):
        if type(obs) is list:
            self.observers.extend(obs)
        else:
            self.observers.append(obs)

    def detach(self, obs):
        self.observers.remove(obs)

    def notify(self, msg):
        for obs in self.observers:
            obs.update(msg)


class Observer(metaclass=ABCMeta):  # 抽象的观察者

    @abstractmethod
    def update(self, notice):
        pass
